package com.gwt.mvp.sample.server.handler;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import com.gwt.mvp.sample.shared.action.IncrementCounterAction;
import com.gwt.mvp.sample.shared.result.IntegerResult;

/**
 * Handler 
 * @author Cristian Miranda
 */
public class IncrementCounterHandler implements ActionHandler<IncrementCounterAction, IntegerResult> {

    public Class<IncrementCounterAction> getActionType() {
        return IncrementCounterAction.class;
    }

    public synchronized IntegerResult execute( IncrementCounterAction action, ExecutionContext context ) throws ActionException {
        return new IntegerResult(Integer.valueOf(action.getAmount() + 1));
    }

    public synchronized void rollback( IncrementCounterAction action, IntegerResult result, ExecutionContext context ) throws ActionException {
        // Reset to the previous value.
    }
}